import fly from './request'

// User
// 用户登录
export function loginByUsername (username, password, openId) {
    let url = `/User/login?userName=${username}&password=${password}&openId=${openId}`

    return fly.request(url, {}, {
        method: 'post'
    })
}

// POST /api/user/loginByOpenId
// 通过openId登陆
export function loginByOpenId (openId) {
    if (openId) {
        let url = `/User/loginByOpenId?openId=${openId}`
        return fly.request(url, {}, {
            method: 'post'
        })
    }
}

// POST /api/user/logout
// 退出登录
export function logout (openId) {
    let url = `/User/logout?openId=${openId}`
    return fly.request(url, {}, {
        method: 'post'
    })
}

// GET /api/user/openId
// 获取openId
export function getOpenId (jsCode) {
    if (jsCode) {
        let url = `/User/openId?jsCode=${jsCode}`
        return fly.request(url, {}, {
            method: 'get'
        })
    }
}

// GET /api/User/UserInfo
// 获取用户信息
export function userInfo () {
    return fly.request('/user/logged', {}, {
        method: 'get'
    })
}

// Insurance
// GET /api/insurance/plans
// 获取投保方案
export function getPlans () {
    return fly.request('/insurance/plans', {}, {
        method: 'get'
    })
}

// POST /api/insurance/checkin
// 入保w2
export function checkin (obj) {
    return fly.request('/insurance/checkin', obj, {
        method: 'post',
        body: JSON.stringify(obj)
    })
}

// POST /api/insurance/checkout
// 入保
// {
// "empId": "string",
//    "planId": "string"
// }
export function checkout (obj) {
    return fly.request('/insurance/checkout', obj, {
        method: 'post',
        body: JSON.stringify(obj)
    })
}

// GET /api/insurance/organization
// 获取公司列表

export function getOrganization (companyId) {
    let url
    !companyId ? url = '/insurance/organization' : url = `/insurance/organization?companyId=${companyId}`
    return fly.request(url, {}, {
        method: 'get'
    })
}

// GET /api/employees
// 花名册

export function employees (pageSize, pageIndex, keyword, orgId, insuranceDate, hasInsurance) {
    let url = `/employees?pageSize=${pageSize}&pageIndex=${pageIndex}&keyword=${keyword}&orgId=${orgId}&insuranceDate=${insuranceDate}&hasInsurance=${hasInsurance}`
    return fly.request(url, { }, {
        method: 'get'
    })
}

// GET /api/insurance/employees
// 在保人员列表

export function getEmployees (pageSize, pageIndex, keyword, orgId, insuranceDate, planId) {
    let url = `/insurance/employees?pageSize=${pageSize}&pageIndex=${pageIndex}&keyword=${keyword}&orgId=${orgId}&insuranceDate=${insuranceDate}&planId=${planId}&_r=${Math.random()}`
    return fly.request(url, {}, {
        method: 'get'
    })
}

// organize
// GET /api/organize/list
// 获取当前登录用户公司列表

export function getOrganizationList (keyword) {
    let url = `/organize/list?keyword=${keyword}`
    return fly.request(url, {}, {
        method: 'get'
    })
}

// POST /api/addorganize
// 新增或者修改公司

export function addOrganize (organizeEntity) {
    let url = `/addorganize`
    return fly.request(url, organizeEntity, {
        method: 'post'
    })
}

// POST /api/updateorganize
// 修复公司信息(只能修改上级，公司名称以及简称)
export function updateOrganize (organizeEntity) {
    let url = `/updateorganize`
    return fly.request(url, organizeEntity, {
        method: 'post'
    })
}

// GET /api/organizeuser
// 获取公司人员信息
export function getDepPersonInfo (orgId, keyword) {
    let url = `/organizeuser?orgId=${orgId}&keyword=${keyword}`
    return fly.request(url, {}, {
        method: 'get'
    })
}

// GET /api/organize/sublist
// 获取下级公司列表
export function sublist (parentId) {
    let url = `/organize/sublist?parentId=${parentId}`
    return fly.request(url, {}, {
        method: 'get'
    })
}

// GET /api/organize/tree
// 获取下级公司树形接口
export function getOrganizeTree () {
    let url = `/organize/tree`
    return fly.request(url, {}, {
        method: 'get'
    })
}

// Case
// 报案
export function reportCase (info) {
    let url = `/case`
    return fly.request(url, info, {
        method: 'post'
    })
}

// POST /api/case/list
// Case
export function caseList (status, pageSize, pageIndex, keyword) {
    let url = `/case/list?status=${status}&pageSize=${pageSize}&pageIndex=${pageIndex}&keyword=${keyword}`
    return fly.request(url, {}, {
        method: 'post'
    })
}

// GET /api/case/claims
// 获取案件材料
export function getCaseClaims (mainId, caseId) {
    let url = `/case/claims?mainId=${mainId}&caseId=${caseId}`
    return fly.request(url, {}, {
        method: 'get'
    })
}

// POST /api/case/claims
// 上传理赔材料
// [
//     {
//         "caseId": "string",
//         "tilte": "string",
//         "files": [
//             {
//                 "fileName": "string",
//                 "fileUrl": "string"
//             }
//         ]
//     }
// ]
export function uploadClaims (claims) {
    let url = `/case/claims`
    return fly.request(url, claims, {
        method: 'post'
    })
}

// POST /api/case/description
// 更新案件描述
export function updateDescription (description, caseId, caseType, hospital) {
    let url = `/case/description?description=${description}&caseId=${caseId}&caseType=${caseType}&hospital=${hospital}`
    return fly.request(url, {}, {
        method: 'post'
    })
}

// POST /api/case/info
// 获取案件信息
export function getCaseInfo (caseId) {
    let url = `/case/info?caseId=${caseId}`
    return fly.request(url, {}, {
        method: 'post'
    })
}

// POST /api/case/upload
// 上传理赔材料
export function upload (claims) {
    let url = `/case/upload`
    return fly.request(url, {}, {
        method: 'post'
    })
}

// GET /api/case/statistics
// 首页案件统计信息
export function statistics () {
    let url = '/case/statistics'
    return fly.request(url, {}, {
        method: 'get'
    })
}

// POST /api/case/claimset
// 加载指定案件理赔材料设定及材料清单
export function claimset (mainId) {
    let url = `/case/claimset?mainId=${mainId}`
    return fly.request(url, {}, {
        method: 'post'
    })
}

// POST /api/case/expresscompanys
// 快递公司编码
export function expresscompanys () {
    let url = `/case/expresscompanys`
    return fly.request(url, {}, {
        method: 'post'
    })
}

// POST /api/case/express
// 增加快递
// {
//     'CaseId': 'string',
//     'RecieveName': 'string',
//     'ExpressCompanyName': 'string',
//     'ExpressCompanyCode': 'string',
//     'ExpressNo': 'string',
//     'ExpressUrl': 'string'
// }
export function express (obj) {
    let url = `/case/express`
    return fly.request(url, obj, {
        method: 'post'
    })
}

// GET /api/insurance/bill
// 获取保费账单
export function getBill (year, month, orgId) {
    let url = `/insurance/bill?year=${year}&month=${month}&orgId=${orgId}`
    return fly.request(url, {}, {
        method: 'get'
    })
}

// GET /api/Insurance/GetInsFee
// 获取保费账单
export function getInsFee (planId, planDate, idNum, hasSecurity, securitycity, workCity) {
    let url = `/insurance/GetInsFee?planId=${planId}&planDate=${planDate}&idNum=${idNum}&hasSecurity=${hasSecurity}&securitycity=${securitycity}&workCity=${workCity}`
    return fly.request(url, {}, {
        method: 'get'
    })
}
